import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
      component: () => import('@/Layout/index.vue'),
      children: [
        {
          path: 'home',
          name: 'home',
          component: () => import('@/views/Home/index.vue'),
          meta: { title: '首页' }
        },
        {
          path: 'discover',
          name: 'discover',
          component: () => import('@/views/Discover/index.vue'),
          meta: { title: '发现' }
        },
        {
          path: 'message',
          name: 'message',
          component: () => import('@/views/Message/index.vue'),
          meta: { title: '消息', requiresAuth: true }
        },
        {
          path: 'my',
          name: 'my',
          component: () => import('@/views/My/index.vue'),
          meta: { title: '我的', requiresAuth: true }
        }
      ]
    },
    // 用户相关路由
    {
      path: '/user',
      component: () => import('@/Layout/DefaultLayout.vue'), // 或者你使用的其他布局组件
      children: [
        {
          path: 'profile',
          name: 'UserProfile',
          component: () => import('@/views/User/Profile.vue'),
          meta: {
            requiresAuth: true,
            title: '个人资料'
          }
        },
        {
          path: 'change-password',
          name: 'ChangePassword',
          component: () => import('@/views/User/ChangePassword.vue'),
          meta: {
            requiresAuth: true,
            title: '修改密码'
          }
        },
        {
          path: 'settings',
          name: 'UserSettings',
          component: () => import('@/views/user/settings.vue'),
          meta: {
            requiresAuth: true,
            title: '设置'
          }
        },
        {
          path: 'participated-activities',
          name: 'ParticipatedActivities',
          component: () => import('@/views/My/ParticipatedActivities.vue'),
          meta: {
            requiresAuth: true,
            title: '我参与的活动'
          }
        },
        {
          path: 'created-activities',
          name: 'CreatedActivities',
          component: () => import('@/views/My/CreatedActivities.vue'),
          meta: {
            requiresAuth: true,
            title: '我发布的活动'
          }
        },
        
      ]
    },
    // 活动详情页面独立路由，不使用 Layout
    {
      path: '/activity/detail/:id',
      name: 'activityDetail',
      component: () => import('@/views/Activity/Detail.vue'),
      meta: { title: '活动详情', hideTabBar: true }
    },
    // 其他活动相关路由
    {
      path: '/activity',
      component: () => import('@/Layout/index.vue'),
      children: [
        {
          path: 'create',
          name: 'activityCreate',
          component: () => import('@/views/Activity/Create.vue'),
          meta: { title: '发布活动', requiresAuth: true }
        },
        {
          path: 'edit/:id',
          name: 'activityEdit',
          component: () => import('@/views/Activity/Edit.vue'),
          meta: { title: '编辑活动', requiresAuth: true }
        },
        {
          path: 'favorites',
          name: 'activityFavorites',
          component: () => import('@/views/Activity/Favorites.vue'),
          meta: { title: '收藏的活动', requiresAuth: true }
        }
      ]
    },
    // 我的活动相关路由
    {
      path: '/my',
      component: () => import('@/Layout/index.vue'),
      children: [
        {
          path: 'activities',
          name: 'myParticipatedActivities',
          component: () => import('@/views/My/Activities.vue'),
          meta: { title: '我参与的活动', requiresAuth: true }
        },
        {
          path: 'created-activities',
          name: 'myCreatedActivities',
          component: () => import('@/views/My/CreatedActivities.vue'),
          meta: { title: '我发布的活动', requiresAuth: true }
        }
      ]
    },
    {
      path: '/auth',
      component: () => import('@/views/auth/layout.vue'),
      children: [
        {
          path: 'login',
          name: 'login',
          component: () => import('@/views/auth/login/index.vue'),
          meta: { title: '登录' }
        },
        {
          path: 'phone-login',
          name: 'phoneLogin',
          component: () => import('@/views/auth/phone-login/index.vue'),
          meta: { title: '手机号登录' }
        },
        {
          path: 'register',
          name: 'register',
          component: () => import('@/views/auth/register/index.vue'),
          meta: { title: '注册' }
        },
        {
          path: 'forgot-password',
          name: 'forgotPassword',
          component: () => import('@/views/auth/forgot-password/index.vue'),
          meta: { title: '忘记密码' }
        }
      ]
    },
    // 404路由
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: () => import('@/views/error/404.vue'),
      meta: { title: '页面不存在' }
    },
  ]
})

export default router

